package com.elinkway.infinitemovies.adapter;

import android.content.Context;
import android.os.Parcelable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.ViewGroup;

import com.elinkway.infinitemovies.bean.VideoDataBean;
import com.elinkway.infinitemovies.ui.fragment.EpisodePageFragment;

import java.util.List;

/**
 * Created by zhaopeipei on 2017/4/13.
 */
public class EpisodePagerAdapter extends FragmentStatePagerAdapter {

    private final static String TAG = "EpisodePagerAdapter";

    private List<String> episodePagerList;

    private Context mContext;

    private int pageIndex = 1;

    private VideoDataBean mVideo;

    private String mSite;

    private boolean mIsGrid;

    private String screenType;

    private EpisodePageFragment mCurrentFragment;

    public EpisodePagerAdapter(FragmentManager fm, Context context, VideoDataBean video, String site, List<String> headerList, boolean isGrid, String screenType) {
        super(fm);
        mContext = context;
        mVideo = video;
        mSite = site;
        episodePagerList = headerList;
        mIsGrid = isGrid;
        this.screenType = screenType;
    }
    @Override
    public int getCount() {
        if (episodePagerList == null || episodePagerList.size() <= 0) {
            return 0;
        } else {
            return episodePagerList.size();
        }
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if(episodePagerList == null || episodePagerList.get(position) == null){
            return "";
        }
        return episodePagerList.get(position).toString();
    }

    @Override
    public void setPrimaryItem(ViewGroup container, int position, Object object) {
        mCurrentFragment = (EpisodePageFragment) object;
        super.setPrimaryItem(container, position, object);
    }

    @Override
    public Fragment getItem(int position) {
        if(episodePagerList == null || episodePagerList.get(position) == null) {
            return null;
        }
        return EpisodePageFragment.getInstance(position + 1, mVideo, mSite, mIsGrid, screenType);
    }

    public EpisodePageFragment getCurrentFragment() {
        return mCurrentFragment;
    }

    public int getItemPosition(Object object){
        return POSITION_NONE;
    }

    @Override
    public void restoreState(Parcelable state, ClassLoader loader) {
        return;
    }

}
